package com.fsds.crem.web.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.fsds.crem.web.dao.AccountInfoDao;
import com.fsds.crem.web.entity.AccountInfo;
import com.fsds.crem.web.entity.ReportAccount;
import com.fsds.crem.web.service.ReportEmailService;

@Service("reportEmailService")
public class ReportEmailServiceImpl implements ReportEmailService {

	@Resource
	private AccountInfoDao accountInfoDao;

	@Override
	public List<AccountInfo> findByNoInstalled(String reportType) {
		
		return accountInfoDao.findByNoInstalled(reportType);
	}

	@Override
	public List<AccountInfo> findByInstalled(String reportType) {
		
		return accountInfoDao.findByInstalled(reportType);
	}

	@Override
	public void saveAddress(String reportType,String empNo) {
		
		// 删除原有收件人
		accountInfoDao.deleteOldAddress(reportType);
		
		// 收件人不为空时，进行保存
		if(StringUtils.isNotEmpty(empNo)){
			
			List<ReportAccount> list = new ArrayList<ReportAccount>();
			for(String no : empNo.split(",")){
				ReportAccount reportAccount = new ReportAccount();
				reportAccount.setReportType(reportType);
				reportAccount.setEmpNo(no);
				list.add(reportAccount);
			}
			
			// 重新保存收件人
			accountInfoDao.saveAddress(list);
		}
	}
}
